package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/admin/category")
@Slf4j
@RestController
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @PutMapping
    @ApiOperation("套餐修改分类管理")
    public Result updateCatergory(@RequestBody CategoryDTO categoryDto) {
        categoryService.updateCategory(categoryDto);
        return Result.success();
    }

    @PostMapping
    @ApiOperation("新增套餐分类管理")
    public Result save(@RequestBody CategoryDTO categoryDTO) {
        categoryService.save(categoryDTO);
        return Result.success();

    }

    @DeleteMapping
    @ApiOperation("删除套餐分类管理")
    public Result<String> delete(Long id) {
        categoryService.delete(id);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    @ApiOperation("套餐状态修改")
    public Result startOrStop(@PathVariable Integer status,Long id){
        categoryService.startOrStop(status,id);
        return Result.success();
    }


    @GetMapping("/page")
    @ApiOperation("分页查询套餐分类管理")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){
        PageResult pageResult=categoryService.pageQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/list")
    @ApiOperation("根据类型查询分类信息")
    public Result<List<Category>> list(Integer type){
        List<Category> list = categoryService.list(type);
        return Result.success(list);
    }

}

